import 防止出现强转无法导包.XueShengBao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");/*获取到输入的账号*/
        String password = request.getParameter("password");/*获取到输入的密码*/
        XueShengBao bao = new XueShengBao(username, password);/*将学生放入一个学生包内*/

        if ("zhanghao".equalsIgnoreCase(username)/*比较这个账号是否和输入的相同IgnoreCase代表不区分大小写*/
            &&"123".equals(password)/*比较密码和输入的是否相等,只有equals代表区分大小写*/){
            HttpSession session = request.getSession();
            session.setAttribute("dengluzhe",bao);/*获取登录人的信息*/

            response.sendRedirect(request.getContextPath()+"/huanying");
        }else {
            request.setAttribute("cuowu","账号或者密码错误");/*创建一个错误信息*/
            /*返回主页面*/
            request.getRequestDispatcher("/login1.jsp").forward(request,response);
        }
    }
}
